/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-07 09:26:03
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-09 17:37:45
 * @FilePath: /yt-devops/lib/pages/devices/device_tab/components/fix_title_width_input.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

class FixTitleWidthInput extends StatefulWidget {
  final double? titleWidth;

  final String title;

  final String? hint;

  final EdgeInsets? formPadding;

  final TextEditingController? controller;

  final TextInputType? textInputType;

  final void Function(String? value)? onChanged;

  const FixTitleWidthInput(
      {super.key,
      this.titleWidth = 90,
      this.title = '',
      this.hint,
      this.controller,
      this.textInputType,
      this.formPadding,
      this.onChanged});

  @override
  State<FixTitleWidthInput> createState() => _FixTitleWidthInputState();
}

class _FixTitleWidthInputState extends State<FixTitleWidthInput> {
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      height: 46.h,
      padding: widget.formPadding ?? EdgeInsets.symmetric(horizontal: 8.w),
      margin: EdgeInsets.only(bottom: 12.h),
      decoration: BoxDecoration(
        border: Border.all(color: Colour.dividerColor),
        borderRadius: BorderRadius.circular(4.w),
      ),
      child: Row(children: [
        Container(
          width: widget.titleWidth,
          padding: EdgeInsets.only(right: 8.w),
          child: Text(
            widget.title,
            style: TextStyles.f14,
          ),
        ),
        Expanded(
            child: TextFormField(
          controller: widget.controller,
          style: TextStyles.f14,
          keyboardType: widget.textInputType,
          textInputAction: TextInputAction.done,
          decoration: InputDecoration(
            hintText: widget.hint ?? ResKey.plsInput.tr,
            counterStyle: TextStyles.f14,
            hintStyle: TextStyles.lf14,
            border: InputBorder.none,
            contentPadding: EdgeInsets.only(bottom: 3.h),
          ),
          onChanged: widget.onChanged,
        ))
      ]),
    );
  }
}
